#include "table/excel.h"
#include "excel_iex.h"
#include "excel_bin.h"
namespace KEngine
{
	ExcelHelp::ExcelHelp(type e):_type(e)
	{
		_excel = 0;
		if(e==type_iex)
		{
			_excel = new ExcelIex();
		}else if(e==type_bin)
		{
			_excel = new ExcelBin();
		}
	}

	ExcelHelp::~ExcelHelp()
	{
		if(_excel)
		{
			delete _excel;
			_excel=0;
		}
	}

	bool ExcelHelp::loadTable(const char *tableName,size_t columnNum)
	{
		return dynamic_cast<ExcelIex*>(_excel)->loadTable(tableName,columnNum);
	}

	void ExcelHelp::setPath(const char* path)
	{
		_excel->setPath(path);
	}

	const ExcelItem* ExcelHelp::getItem(const char *tableName,size_t line)const
	{
		return _excel->getItem(tableName,line);
	}
	const ExcelItem* ExcelHelp::getItem(const char *tableName,const char *rowName) const
	{
		return _excel->getItem(tableName,rowName);
	}
	const ExcelItem* ExcelHelp::getItem(const char *tableName,const char *rowName,const char* columnName) const
	{
		return _excel->getItem(tableName,rowName,columnName);
	}

	int ExcelHelp::getRowNum(const char* tableName)
	{
		const Table* p = _excel->findTable(tableName);
		if(!p)
			return -1;
		p->getRowNum();
	}

	int ExcelHelp::getColumnNum(const char* tableName)
	{
		const Table* p = _excel->findTable(tableName);
		if(!p)
			return -1;
		p->getColumnNum();
	}

	bool ExcelHelp::loadEnum(const char *enumFile, bool defaultValue)
	{
		return _excel->loadEnum(enumFile,defaultValue);
	}

	const Table* ExcelHelp::getTable(const char *tableName)
	{
		return _excel->findTable(tableName);
	}

	void ExcelHelp::save2bin()
	{
		dynamic_cast<ExcelIex*>(_excel)->save2bin();
	}

	void ExcelHelp::loadFrombin()
	{
		dynamic_cast<ExcelBin*>(_excel)->loadFromBin();
	}
};
